﻿import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { {{class_name}}Dto } from '../../proxy/joy/erp/{{to_kebab_case(project_group_name)}}/{{to_kebab_case(parent_menu)}}';

@Component({
  selector: 'lib-{{to_kebab_case(class_name)}}-ref-entity',
  templateUrl: './{{to_kebab_case(class_name)}}-ref-entity.component.html',
})
export class {{class_name}}RefEntityComponent implements OnInit {
  validateForm: FormGroup;
  @Input() model: {{class_name}}Dto;
  constructor(public fb: FormBuilder, public modalRef: NzModalRef) {}

  ngOnInit(): void {
    this.validateForm = this.fb.group({
      {{~ for property in exclude_propertys(self_value_propertys, "TenantId", "Level", "ParentId") ~}}
      {{to_camel_case(property.name)}}: [this.model?.{{to_camel_case(property.name)}}, [Validators.required]],
      {{~ end ~}}
    });
  }

  cancelForm() {
    this.modalRef.close(null);
  }

  submitForm() {
    if (!this.validateForm.valid) return;
    this.modalRef.close({
      ...this.model,
      ...this.validateForm.value,
    });
  }
}
